import { asyncRoutes } from '../../router';

const state = {
  routes: []
};

const mutations = {
  SET_ROUTES: (state, routes) => {
    state.routes = routes;
  }
};

const actions = {
  // 模拟动态路由生成，对接后台接口可做路由权限的比对
  async generateRoutes({ commit }) {
    return new Promise((resolve, reject) => {
      const accessedRoutes = asyncRoutes;
      commit('SET_ROUTES', accessedRoutes);
      resolve(accessedRoutes);
    });
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
